<?php
class MySearchAnalyzer implements Doctrine_Search_Analyzer_Interface
{
  protected static $_stopwords = array('de', 'con', 'el');
  
  public function analyze($text)
  {
    $text = preg_replace('/[\'`´"]/', '', $text);
    $text = Doctrine_Inflector::unaccent($text);
    $text = preg_replace('/[^A-Za-z0-9]/', ' ', $text);
    $text = str_replace('  ', ' ', $text);

    $terms = explode(' ', $text);
  
    $ret = array();
    if ( ! empty($terms)) 
    {
      foreach ($terms as $i => $term) 
      {
        if (empty($term)) { continue; }
        $lower = strtolower(trim($term));

        if (in_array($lower, self::$_stopwords)) { continue; }
        $ret[$i] = $lower;
      }
    }
    return $ret;
  }
}
